<?php
defined('_JEXEC') or die;

class ModDoskaCategoriesHelper {
	
	
	public static function getList() {
		
		$list = array();
		
		$db = JFactory::getDbo();
		$query = $db->getQuery(TRUE);
		
		$query->select('id,name,alias,parentid');
		$query->from('#__doska_categories');
		$query->where('state = 1');
		$query->order('ordering'. ' '. 'ASC');
		
		$db->setQuery($query);
		
		$categories = $db->loadObjectList();
		
		/*
		JModelLegacy::addIncludePath(JPATH_ADMINISTRATOR.'/components/com_doska/models','DoskaModel');
		$model = JModelLegacy::getInstance('Categories','DoskaModel');
		$model->getState();
		$model->setState('list.limit',0);
		$model->setState('cat.state',1);
		
		$categories = $model->getItems();*/
		
		
		if(!array($categories)) {
			return FALSE;
		}
		
		foreach($categories as $row) {
			if(!$row->parentid) {
				$list[$row->id]['name'] = $row->name;
				$list[$row->id]['alias'] = $row->alias;
			}
			else {
				$list[$row->parentid]['next'][] = array(
														
														'id'=>$row->id,
														'name'=>$row->name,
														'alias'=>$row->alias
														);
			}
			
		}
		
		return $list;
	}
}